<template>
  <div id="activeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="搜索：" prop="activityName">
          <el-select
            v-model="formInline.activityName"
            filterable
            clearable
            placeholder="请输入活动名称"
          >
            <el-option
              v-for="item in activeList"
              :key="item.id"
              :label="item.activityName"
              :value="item.activityName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态：" prop="activityStatus">
          <el-select
            v-model="formInline.activityStatus"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in statusOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间：" prop="time">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getActivitiesNameList } from '@/api/operate/collectPraise.js'

export default {
  watch: {
    'formInline.time': {
      immediate: true,
      handler(newV, oldV) {
        if (newV == null) {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        } else {
          this.formInline.startTime = newV[0]
          this.formInline.endTime = newV[1]
        }
      },
      deep: true
    }
  },
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          activityName: '',
          activityStatus: '',
          endTime: '',
          startTime: '',
          time: []
        }
      }
    }
  },
  data() {
    return {
      time: [],
      checkCollege: '',
      collegeList: [],
      activeList: [],
      statusOptions: [
        { dictLabel: '全部', dictValue: '' },
        { dictLabel: '未开始', dictValue: 'NOT_STARTED' },
        { dictLabel: '进行中', dictValue: 'ONGOING' },
        { dictLabel: '已结束', dictValue: 'OVER' }
      ],
      activesOptions: [],
      activesValue: '',
      statusValue: '',
      userType: [],
      rules: {
        activityName: {},
        activityStatus: {},
        time: []
      }
    }
  },
  mounted() {
    this.getColleges()
    this.getActivesTypes()
    // this.getActivesStates()
    this.getActivitiesNameListMethods()
  },
  methods: {
    getActivitiesNameListMethods() {
      getActivitiesNameList(
        (response) => {
          this.activeList = response
        },
        (response) => {
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    // async getActivesStates() {
    //   let data = await sysNormalDisable(
    //     'marketing_activity_state',
    //     'marketing_activity_state'
    //   )
    //   let addAll = [{ dictLabel: '全部', dictValue: '' }]
    //   this.statusOptions = addAll.concat(data)
    // },
    async getActivesTypes() {
      let data = await sysNormalDisable(
        'specific_marketing_activity_type',
        'specific_marketing_activity_type'
      )
      let slectData = data.filter((item) => {
        return item.dictValue !== 'INVITE_ACTIVITY'
      })
      let addAll = [{ dictLabel: '全部', dictValue: '' }]
      this.activesOptions = addAll.concat(slectData)
    },
    async getColleges() {
      let data = await sysNormalDisable('sys_college', 'sys_college')
      let addAll = [{ dictLabel: '全部', dictValue: '' }]
      this.collegeList = addAll.concat(data)
    },
    toSearch(formName) {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.search-box :deep(.el-input__inner) {
  padding: 0 30px;
}
</style>
